import store from "@/store";
import router from "@/router";

router.beforeEach(async (to, from, next) => {
  //to:你想要跳转过去的路由
  //from:你从那个路由而来
  //next:其实是一个函数【放行函数】  放行函数有几种写法:next()   A->B next           next('/detail') 指定跳转到某一个路由
  let hasToken = store.state.user.token;
  if (hasToken) {
    if (to.path == "/center") {
      next("/loginsuccess");
    } else {
      next();
    }
  } else {
    next();
  }
});
